package com.service.gmall.product.controller;

import com.service.gmall.common.result.Result;
import com.service.gmall.model.product.BaseAttrInfo;
import com.service.gmall.model.product.BaseAttrValue;
import com.service.gmall.product.service.BaseAttrInfoService;
import com.service.gmall.product.service.BaseAttrValueService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author alpha
 * @className: AttrInfoController
 * @date 2022/8/23 11:16
 * @Description :平台属性接口
 */
@Api(tags = "平台属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseAttrInfoController {

    @Autowired
    BaseAttrInfoService baseAttrInfoService;
    @Autowired
    BaseAttrValueService baseAttrValueService;
    // admin/product/attrInfoList/1/1/0
    /**
     * @param category1Id  一级分类ID
     * @param category2Id   二级分类ID
     * @param category3Id   三级分类ID
     * @description: 根据分类id获取平台属性
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 0:21
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getAttrInfoList(@PathVariable("category1Id")Long category1Id,
                                  @PathVariable("category2Id")Long category2Id,
                                  @PathVariable("category3Id")Long category3Id){
        List<BaseAttrInfo> baseAttrInfos = baseAttrInfoService.getAttrInfoList(category1Id,category2Id,category3Id);

        return Result.ok(baseAttrInfos);
    }

//    admin/product/saveAttrInfo
    /**
     * @param info
     * @description: 保存平台属性或者修改平台属性
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 1:29
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo info){
        baseAttrInfoService.saveAttrInfo(info);
        return Result.ok();
    }
    /**
     * @param attrId 平台属性ID
     * @description: 根据平台属性ID获取平台属性对象数据
     * @return: com.service.gmall.common.result.Result
     * @author: alpha
     * @date: 2022/8/24 1:57
     */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId){
        List<BaseAttrValue> value = baseAttrValueService.getAttrValueList(attrId);
        return Result.ok(value);
    }
}
